﻿Public Class PageVerify
	Public Shared Function PageExists(ByVal URL As String, ByVal verifyLink As Boolean) As Boolean
		If verifyLink = False Then
			Return True
		End If

		'Code leached and converted from http://blogs.microsoft.co.il/blogs/dorr/archive/2008/09/02/how-to-check-if-a-file-exists-over-http.aspx
		Try
			Dim request = System.Net.HttpWebRequest.Create(URL)
			request.Method = "HEAD"	' Just get the document headers, not the data.    
			request.Credentials = System.Net.CredentialCache.DefaultCredentials

			'This may throw a WebException:    
			Using response As System.Net.HttpWebResponse = CType(request.GetResponse(), System.Net.HttpWebResponse)

				If response.StatusCode = System.Net.HttpStatusCode.OK Then
					Return True
				Else
					Return False
				End If

			End Using

		Catch ex As System.Net.WebException
			Dim webResponse As System.Net.HttpWebResponse = CType(ex.Response, System.Net.HttpWebResponse)

			'// Determine the cause of the exception, was it 404?    
			If webResponse.StatusCode = System.Net.HttpStatusCode.NotFound Then
				Return False
			Else
				Return True
			End If

		End Try


	End Function

	Private Sub New()

	End Sub


End Class
